//
//  YeeBadgeLable.swift
//  YouCaiShoppingMall
//
//  Created by 优裁科技 on 2017/10/18.
//  Copyright © 2017年 优裁科技. All rights reserved.
//

import UIKit

/**
 * YeeBadgeLable
 */
class YeeBadgeLable : UILabel {

    func makeBrdgeViewWithText(text:String, textColor tColor:UIColor,  backColor bColor:UIColor = UIColor.init().colorFromHexInt(hex: 0xed8348), textFont font:UIFont, tframe frame:CGRect) {

        if (text.count > 0) {
            let x_margin:CGFloat = frame.size.width - 10
            let y_margin:CGFloat = frame.size.height - 10

            self.frame = .init(x: frame.origin.x + x_margin * 0.5, y: frame.origin.y + y_margin * 0.5, width: 10, height: 10)
        }
        else{
            self.frame=frame;
        }

        self.backgroundColor = bColor
        self.textColor = tColor
        self.font = font
        self.text = text
        self.textAlignment = .center

        //创建mask层，超出的部分将不显示
        let path:UIBezierPath = UIBezierPath.init(roundedRect: self.bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize.init(width: self.frame.size.height * 0.5, height: self.frame.size.height * 0.5))

        let maskLayer:CAShapeLayer = CAShapeLayer.init()
        maskLayer.frame = self.bounds
        maskLayer.path = path.cgPath
        self.layer.mask = maskLayer
    }

    func makeBrdgeViewWithCor(corner:CGFloat, CornerColor cornerColor:UIColor){

        let path:UIBezierPath = UIBezierPath.init(roundedRect: self.bounds, byRoundingCorners: UIRectCorner.allCorners, cornerRadii: CGSize.init(width: corner, height: corner))

        self.backgroundColor = cornerColor
        let maskLayer:CAShapeLayer = CAShapeLayer.init()
        maskLayer.frame = self.bounds
        maskLayer.path = path.cgPath
        self.layer.mask = maskLayer
    }
}
